﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Core
{
    public static partial class contest
    {
        public static dynamic deleteContest(int cid)
        {
            var sql = new Sql.SqlDataContext();
            var p = sql.Contest.FirstOrDefault(r => r.cid == cid);
            if(p == null)
            {
                return new{
                    success = false,
                    msg = "比赛不存在"
                };
            }
            //Delete Status
            var sts = sql.ContestStatus.Where(row => row.cid == cid);
            if(sts != null) sql.ContestStatus.DeleteAllOnSubmit(sts);

            //Delete Problem
             var pro = sql.ContestProblem.Where(row => row.cid == cid);
            if (pro != null) sql.ContestProblem.DeleteAllOnSubmit(pro);

            //Delete Solve
            var sol = sql.ContestSolve.Where(row => row.cid == cid);
            if(sol != null) sql.ContestSolve.DeleteAllOnSubmit(sol);

            var con = sql.Contest.Where(row => row.cid == cid);
            if(con != null) sql.Contest.DeleteAllOnSubmit(con);

            sql.SubmitChanges();
            return new
            {
                success = true
            };
        }
    }
}
